#ifndef DOWNLOADFILE_H
#define DOWNLOADFILE_H

#include <QObject>
#include <QNetworkAccessManager>
#include <QFile>
#include <QUrl>

class DownloadFile : public QObject
{
    Q_OBJECT
    Q_ENUMS(Status)

    Q_PROPERTY(Status status READ status NOTIFY statusChanged)
    Q_PROPERTY(QString file READ file)

public:
    enum Status { Null, Ready, Loading, Error };
    explicit DownloadFile(QObject *parent=0);
    ~DownloadFile() {}

    Status status() const;
    QString file() const;

    Q_INVOKABLE void downloadFile(QUrl url, QString fileName);
    Q_INVOKABLE bool checkFile(QString fileName);
    Q_INVOKABLE QString errorString();

signals:
    void ready(QString fileName);
    void statusChanged(DownloadFile::Status);

public slots:
    void fileIsReady(QNetworkReply * reply);

public:
    QNetworkAccessManager manager;
    QString m_fileName;
    QFile m_file;
    QString m_error;
    DownloadFile::Status m_status;
};
#endif // DOWNLOADFILE_H
